<template>
	<view>
		<!-- #ifdef APP-PLUS -->
		<view>
			<uni-nav-bar title="合伙人登录" :statusBar='true' :fixed="true"></uni-nav-bar>
		</view>
		<!-- #endif -->
		<view class="login-box">
			<view class="login-box-top">
				<image src="../../static/login/msjimg.png"></image>
				<view class="login-box-top-text">结账都是会员价</view>
			</view>
			<view class="login-box-center">
				<view class="login-box-center-phone">
					<view class="login-box-center-phone-86">+86</view>
					<input type="text" v-model="phone" placeholder="输入手机号码" class="login-box-center-phone-input" placeholder-style="color:#AAAAAA" />
				</view>
				<view class="login-box-center-password">
					<view class="login-box-center-password-left">
						<input type="password" v-model="password" placeholder="输入密码" placeholder-style="color:#AAAAAA" />
					</view>
					<view class="login-box-center-password-right">
						<button @click="goRetrievepasswordPage">找回密码</button>
					</view>
				</view>
				<view class="login-box-center-login">
					<button @click="mylogin">登陆</button>
					<text @click="goVerificationcodeloginPage">使用短信验证码登录</text>
				</view>
			</view>
			<view class="login-box-bottom">
				<view class="login-box-bottom-title">
					<view class="login-box-bottom-title-xianl"></view>
					<view class="login-box-bottom-title-text">快速登录</view>
					<view class="login-box-bottom-title-xianr"></view>
				</view>
				<view class="login-box-bottom-party-login">
					<image src="../../static/login/wximg.png"></image>
				</view>
				<view class="login-box-bottom-agreement">
					<view>注册即同意<text>《用户协议》</text>和<text>《隐私策略》</text></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { config } from '@/utils/config.js'
	import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
	export default {
		components: {
			uniNavBar
		},
		data() {
			return {
				phone: '',
				password: ''
			}
		},
		methods: {
			// 手机号+密码登录
			mylogin() {
				const phone = this.phone
				const password = this.password
				// 手机号
				if (phone === '') {
					uni.showToast({
						title: '手机号码不能为空',
						icon: 'none'
					})
					return false
				}
				// 验证密码
				if (password === '') {
					uni.showToast({
						title: '密码不能为空',
						icon: 'none'
					})
					return false
				}
				if (!(/^1[345678]\d{9}$/.test(this.phone))) {
					uni.showToast({
						title: '手机号码格式错误',
						icon: 'none'
					})
					return false
				}
				uni.request({
					url: `${config.api_base_url}agent/agent/login`,
					method: 'POST',
					data: {
						phone: phone,
						password: password
					},
					success: ((res) => {
						let { status, data } = res.data
						if (status.flag === true) {
							uni.setStorageSync('d_role', data.role)
							uni.setStorageSync('d_token', data.token)
							uni.showToast({
								title: '登录成功',
								icon: 'none'
							})
							uni.switchTab({
								url:"/pages/index/index"
							})
						} else {
							uni.showToast({
								title: status.msg,
								icon: 'none'
							})
						}
					}),
					fail: (() => {
						uni.showToast({
							title: '网络异常, 请重新登录',
							icon: 'none'
						});
					})
				});
			},
			// 跳转到手机加短信验证码登录页面
			goVerificationcodeloginPage() {
				uni.redirectTo({
					url: '../verificationcodelogin/verificationcodelogin'
				})
			},
			// 跳转到找回密码页面
			goRetrievepasswordPage() {
				uni.navigateTo({
					url: '../retrievepassword/retrievepassword'
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
<style scoped>
	.login-box {
		border-top: 2rpx solid rgba(0, 0, 0, 0.05);
		padding-bottom: 60rpx;
		box-sizing: border-box;
	}

	.login-box-top {
		padding-top: 88rpx;
		box-sizing: border-box;
	}

	.login-box-top image {
		width: 144rpx;
		height: 144rpx;
		display: block;
		margin: 0px auto;
	}

	.login-box-top-text {
		font-size: 28rpx;
		letter-spacing: 3rpx;
		line-height: 40rpx;
		color: rgba(36, 36, 36, 1);
		text-align: center;
		margin-top: 38rpx;
	}

	.login-box-center {
		padding: 130rpx 60rpx 0rpx;
		box-sizing: border-box;
	}

	.login-box-center-phone {
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.05);
		display: flex;
		align-items: center;
		padding: 20rpx 0rpx;
		box-sizing: border-box;
	}

	.login-box-center-phone-86 {
		height: 44rpx;
		font-size: 32rpx;
		font-weight: 600;
		color: rgba(36, 36, 36, 1);
		line-height: 44rpx;
		width: 140rpx;
	}

	.login-box-center-phone-input {
		height: 44rpx;
		font-size: 32rpx;
		color: rgba(36, 36, 36, 1);
		line-height: 44rpx;
	}

	.login-box-center-password {
		padding: 20rpx 0rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.login-box-center-password-left {
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.05);
		padding: 20rpx 0rpx;
		box-sizing: border-box;
	}

	.login-box-center-password-left input {
		height: 44rpx;
		font-size: 32rpx;
		color: rgba(36, 36, 36, 1);
		line-height: 44rpx;
	}

	.login-box-center-password-right {
		padding: 20rpx 0rpx;
		box-sizing: border-box;
	}

	.login-box-center-password-right button {
		line-height: 40rpx;
		height: 40rpx;
		font-size: 28rpx;
		width: 116rpx;
		background: #fff;
		border: none;
		padding: 0px;
		box-sizing: border-box;

	}

	.login-box-center-password-right button::after {
		border: none;
	}

	.login-box-center-login {}

	.login-box-center-login button {
		width: 482rpx;
		height: 84rpx;
		background: rgba(240, 34, 48, 1);
		border-radius: 42rpx;
		font-size: 28rpx;
		line-height: 84rpx;
		color: rgba(255, 255, 255, 1);
		margin: 108rpx auto 48rpx;
		letter-spacing: 4rpx;
	}

	.login-box-center-login text {
		height: 36rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: rgba(36, 36, 36, 1);
		line-height: 36rpx;
		text-align: center;
		width: 100%;
		display: block;
		letter-spacing: 3rpx;

	}

	.login-box-bottom {
		margin-top: 40rpx;
	}

	.login-box-bottom-title {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.login-box-bottom-title-xianl {
		width: 284rpx;
		height: 2rpx;
		background: rgba(0, 0, 0, 0.05);
		margin-top: 2rpx;
	}

	.login-box-bottom-title-text {
		width: 120rpx;
		height: 36rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: rgba(170, 170, 170, 1);
		line-height: 36rpx;
		text-align: center;
	}

	.login-box-bottom-title-xianr {
		width: 284rpx;
		height: 2rpx;
		background: rgba(0, 0, 0, 0.05);
		margin-top: 2rpx;
	}

	.login-box-bottom-party-login {}

	.login-box-bottom-party-login image {
		width: 68rpx;
		height: 68rpx;
		display: block;
		margin: 46rpx auto 68rpx;
	}

	.login-box-bottom-agreement {
		text-align: center;
	}

	.login-box-bottom-agreement view {
		height: 36rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: rgba(170, 170, 170, 1);
		line-height: 36rpx;
	}

	.login-box-bottom-agreement view text {
		height: 36rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: rgba(102, 172, 255, 1);
		line-height: 36rpx;
	}
</style>
